#coding=utf-8
'''
Transforming and Reducing Data at the Same Time

A very elegant way to combine a data reduction and a transformation is to use a
generator-expression argument.
'''
nums = [1, 2, 3, 4, 5]
s = sum(x * x for x in nums)
print(s)

# Determine if any .py files exist in a directory
import os
files = os.listdir('E:\\pycodes\\Test\\algorithm')
a = [name.endswith('.py') for name in files]
print(a)
print(any(a))
if any(name.endswith('.py') for name in files):
    print('There be python!')
else:
    print('Sorry, no python.')

# Output a tuple as CSV
s = ('ACME', 50, 123.45)
print(','.join(str(x) for x in s))

# Data reduction across fields of a data structure
porfolio = [
    {'name':'GOOG', 'shares': 50},
    {'name':'YHOO', 'shares': 75},
    {'name':'AOL', 'shares': 20},
    {'name':'SCOX', 'shares': 65}
]
min_shares = min(s['shares'] for s in porfolio)
min_shares2 = min(property, key=lambda s: s['shares'])
print(min_shares)

